﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BuyThePeople.Models;

namespace BuyThePeople.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            DataModelsDataContext dmdc = new DataModelsDataContext();

            GoodsList gListNew = new GoodsList();
            GoodsList gListOrder = new GoodsList();
            GoodsList gListClose = new GoodsList();

            Dictionary<string, GoodsList> dic = new Dictionary<string, GoodsList>();

            gListNew.goods = dmdc.T_GOODS.OrderByDescending(x => x.RegDate).ToList();
            gListNew.itemCount = 4;
            gListNew.CalcPage();
            dic.Add("new", gListNew);

            gListOrder.goods = dmdc.T_GOODS.OrderByDescending(x => dmdc.T_JOINTPURCHASE.Count(item => item.GoodsSeq == x.GoodsSeq)).ToList();
            gListOrder.itemCount = 4;
            gListOrder.CalcPage();
            dic.Add("order", gListOrder);

            gListClose.goods = dmdc.T_GOODS.OrderByDescending(x => x.BidDateEnd - new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)).ToList();
            gListClose.itemCount = 4;
            gListClose.CalcPage();
            dic.Add("close", gListClose);

            return View(dic);
        }

        public ActionResult _Layout()
        {
            return View();
        }

        public ActionResult _ViewStart()
        {
            return View();
        }

        public ActionResult TestPage()
        {
            

            DataModelsDataContext c = new DataModelsDataContext();
            ViewBag.a = c.T_USER.GetEnumerator();



            return View(c.T_USER.GetEnumerator());
        }

        public ActionResult ViewPage1()
        {
            DataModelsDataContext c = new DataModelsDataContext();

            //T_USER u = new T_USER();
            //u.Name = "홍길동";
            //u.ID = "user1";
            //c.T_USER.InsertOnSubmit(u);
            return View(c.T_USER.ToList());
        }

        public ActionResult Error()
        {
            return View();
        }
    }
}
